package com.jjb.saas.gen.controller;

import cn.hutool.json.JSONUtil;
import com.jjb.saas.gen.service.GenTabelServiceI;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 代码生成工具
 * @Author: WGG
 * @Date: 2022/3/26 15:03
 */
@RestController
@AllArgsConstructor
@RequestMapping("/gen")
public class GenController {

    private final String RES_SUCCESS = "成功";
    private final String RES_ERROR = "失败";

    private final GenTabelServiceI genTabelServiceI;
    /**
     * 导入表结构（保存）
     */
    @GetMapping("/importTable/{tables}")
    public String importTableSave(@PathVariable("tables") String tables)
    {
        String[] tableNames = tables.split(",");
        genTabelServiceI.saveGenTableInfo(tableNames);
        return RES_SUCCESS;
    }



    /**
     * 生成代码（自定义路径）
     */
    @GetMapping("/{tableName}")
    public String genCode(@PathVariable("tableName") String tables)
    {
        String[] tableNames = tables.split(",");

        for (String tableName : tableNames) {
            genTabelServiceI.generatorCode(tableName);
        }

        return RES_SUCCESS;
    }

   /* @PostMapping("/pdm")
    public String genCodeByPdman(@RequestBody PdmanJsonCmd pdmanJsonCmd){
       return genTabelServiceI.generatorPdm(pdmanJsonCmd);
    }*/
}
